package com.jstyle.beatecg.util;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.text.TextUtils;
import android.util.Log;

import com.jstyle.beatecg.R;
import com.jstyle.beatecg.model.HrvData;
import com.jstyle.beatecg.model.PathRecord;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import lecho.lib.hellocharts.gesture.ContainerScrollType;
import lecho.lib.hellocharts.gesture.ZoomType;
import lecho.lib.hellocharts.model.Axis;
import lecho.lib.hellocharts.model.AxisValue;
import lecho.lib.hellocharts.model.Column;
import lecho.lib.hellocharts.model.ColumnChartData;
import lecho.lib.hellocharts.model.ColumnValue;
import lecho.lib.hellocharts.model.Line;
import lecho.lib.hellocharts.model.LineChartData;
import lecho.lib.hellocharts.model.PointValue;
import lecho.lib.hellocharts.model.Viewport;
import lecho.lib.hellocharts.view.AbstractChartView;

/**
 * Created by Administrator on 2018/6/4.
 */

public class ChartDataUtil {
    private static final String TAG = "ChartDataUtil";
    public static int StrokeWidth =1;

    /**图表初始化
     * @param chart
     * @param left
     * @param top
     * @param right
     * @param bottom
     */
    public static void initChartView(AbstractChartView chart, float left, float top, float right, float bottom) {
        Viewport viewport = chart.getCurrentViewport();
        viewport.top = top;
        viewport.bottom = bottom;
        viewport.left = left;
        viewport.right = right;
        chart.setContainerScrollEnabled(false, ContainerScrollType.HORIZONTAL_IN_ScrollView);
        chart.setViewportCalculationEnabled(false);
        chart.setMaximumViewport(viewport);
        chart.setZoomType(ZoomType.HORIZONTAL);
        chart.setCurrentViewport(viewport, false);
    }


    /**
     * 设置一个屏幕展示数据量
     * @param size
     * @param chartView
     */
    public static void settingXb(int size,AbstractChartView chartView){
        if(size>7){
            Viewport v = new Viewport(chartView.getMaximumViewport());
            chartView.setMaximumViewport(v); //这2个属性的设置一定要在lineChart.setMaximumViewport(v);
            // 这个方法之后,不然显示的坐标数据是不能左右滑动查看更多数据的
            v.left = size - 7;
            v.right = size ;
            chartView.setCurrentViewport(v,true);
        }
    }

    /**健康记录平均心率
     * @param context
     * @return
     */
    public static LineChartData getAvgHeartChart(Context context,String[]axisArray,HashMap<String,Integer>maxHashMap,HashMap<String,Integer>minHashMap){
        Axis axisX = new Axis();
        Axis axisY = new Axis();
        axisY.setTextSize(10);
        axisX.setTextSize(10);
        int maxColor = context.getResources().getColor(R.color.history_maxheart);
        int avgColor = context.getResources().getColor(R.color.history_avgheart);
        int minColor = context.getResources().getColor(R.color.history_minheart);
        String[]weekArray=context.getResources().getStringArray(R.array.week_chart);
        List<AxisValue> axisesY = new ArrayList<>();
        List<AxisValue> axises = new ArrayList<>();
        Line maxLine = new Line();
        Line avgLine = new Line();
        Line minLine = new Line();
        List<PointValue> maxPoints = new ArrayList<>();
        List<PointValue> avgPoints = new ArrayList<>();
        List<PointValue> minPoints = new ArrayList<>();

        for(int i=0;i<7;i++){
            int position=40+i*20;
            axisesY.add(new AxisValue(position).setLabel(String.valueOf(position).toCharArray()));
        }
        int length=axisArray.length;
        for(int i=0;i<length;i++){
            axises.add(new AxisValue(i).setLabel(length>7?String.valueOf(i+1).toCharArray():weekArray[i].toCharArray()));
            String time=axisArray[i];
            Integer max=maxHashMap.get(time);
            if(max!=null){
                maxPoints.add(new PointValue(i,max));
            }else{
                maxPoints.add(new PointValue(i,0));
            }
            Integer min=minHashMap.get(time);
            if(min!=null){
                minPoints.add(new PointValue(i,min));
                int avg=(max+min)/2;
                avgPoints.add(new PointValue(i,avg));
            }else{
                minPoints.add(new PointValue(i,0));
                avgPoints.add(new PointValue(i,0));
            }
        }
        axisY.setValues(axisesY).setTextColor(Color.WHITE);
        axisY.setHasLines(false);
        axisX.setValues(axises).setTextColor(Color.WHITE);
        List<Line> lines = new ArrayList<>();

        maxLine.setValues(maxPoints)
                .setCubic(true)
                .setStrokeWidth(StrokeWidth)
                .setHasPoints(false)
                .setColor(maxColor).setFilled(true).setAreaTransparency(255);
        avgLine.setColor(avgColor)
                .setCubic(true)
                .setValues(avgPoints)
                .setHasPoints(false)
                .setStrokeWidth(StrokeWidth).setFilled(true).setAreaTransparency(255);
        minLine.setColor(minColor)
                .setCubic(true)
                .setValues(minPoints)
                .setHasPoints(false)
                .setStrokeWidth(StrokeWidth).setFilled(true).setAreaTransparency(255);
        LineChartData lineChartData = new LineChartData();
        lineChartData.setAxisXBottom(axisX);
        lineChartData.setAxisYLeft(axisY);
        lineChartData.setValueLabelBackgroundEnabled(false);
        lines.add(maxLine);
        lines.add(avgLine);
        lines.add(minLine);
        lineChartData.setLines(lines);
        return lineChartData;
    }
    public static LineChartData getDayAvgHeartChart(Context context,List<HrvData>list){
        Axis axisX = new Axis();
        Axis axisY = new Axis();
        axisY.setTextSize(10);
        axisX.setTextSize(10);
        int maxColor = context.getResources().getColor(R.color.history_maxheart);
        int avgColor = context.getResources().getColor(R.color.history_avgheart);
        int minColor = context.getResources().getColor(R.color.history_minheart);

        List<AxisValue> axisesY = new ArrayList<>();
        List<AxisValue> axises = new ArrayList<>();
        Line maxLine = new Line();
        Line avgLine = new Line();
        Line minLine = new Line();
        List<PointValue> maxPoints = new ArrayList<>();
        List<PointValue> avgPoints = new ArrayList<>();
        List<PointValue> minPoints = new ArrayList<>();

        for(int i=0;i<7;i++){
            int position=40+i*20;
            axisesY.add(new AxisValue(position).setLabel(String.valueOf(position).toCharArray()));
        }
        int length=list.size();
        for(int i=0;i<length+1;i++){
            if(i==length){
                maxPoints.add(new PointValue(i,0));
                minPoints.add(new PointValue(i,0));
                avgPoints.add(new PointValue(i,0));
                break;
            }
            HrvData hrvData=list.get(i);
            String time=hrvData.getTime();
            axises.add(new AxisValue(i).setLabel(time.split(" ")[1].toCharArray()));
            maxPoints.add(new PointValue(i,hrvData.getMaxHeart()));
            minPoints.add(new PointValue(i,hrvData.getMinHeart()));
            avgPoints.add(new PointValue(i,hrvData.getAvgHeart()));
        }
        if(list.size()==0) axises.add(new AxisValue(1).setLabel(" ".toCharArray()));

        axisY.setValues(axisesY).setTextColor(Color.WHITE);
        axisY.setHasLines(false);
        axisX.setValues(axises).setTextColor(Color.WHITE);
        List<Line> lines = new ArrayList<>();
        maxLine.setValues(maxPoints)
                .setCubic(true)
                .setStrokeWidth(StrokeWidth)
                .setHasPoints(false)
                .setColor(maxColor).setFilled(length!=0).setAreaTransparency(255);
        avgLine.setColor(avgColor)
                .setCubic(true)
                .setValues(avgPoints)
                .setHasPoints(false)
                .setStrokeWidth(StrokeWidth).setFilled(length!=0).setAreaTransparency(255);
        minLine.setColor(minColor)
                .setCubic(true)
                .setValues(minPoints)
                .setHasPoints(false)
                .setStrokeWidth(StrokeWidth).setFilled(length!=0).setAreaTransparency(255);
        LineChartData lineChartData = new LineChartData();
        lineChartData.setAxisXBottom(axisX);
        lineChartData.setAxisYLeft(axisY);
        lineChartData.setValueLabelBackgroundEnabled(false);
        lines.add(maxLine);
        lines.add(avgLine);
        lines.add(minLine);
        lineChartData.setLines(lines);
        return lineChartData;
    }


    public static LineChartData getDayHrvChart(Context context, List<HrvData> list,int showType){
        Axis axisX = new Axis();
        Axis axisY = new Axis();
        axisY.setTextSize(10);
        axisX.setTextSize(10);
        if(LanguageHelp.isEnglish()){
            axisY.setMaxLabelChars(6);
        }else{
            axisY.setMaxLabelChars(2);
        }
        int color =  Color.parseColor("#05a0ff");;
        List<AxisValue> axisesY = new ArrayList<>();
        String[]array=context.getResources().getStringArray(R.array.history_hrvchart);
        String[] weekArrays = context.getResources().getStringArray(R.array.week_chart);
        for(int i=0;i<3;i++){
            float position=i+0.5f;
            axisesY.add(new AxisValue(position).setLabel(array[i].toCharArray()));
        }
        List<AxisValue> axises = new ArrayList<>();
        int length=list.size();
//        for (int i = 0; i < length; i++) {
//            axises.add(new AxisValue(i).setLabel(length>7?String.valueOf(i+1).toCharArray():weekArrays[i].toCharArray()));
//        }
        axisY.setValues(axisesY).setTextColor(Color.WHITE);
        axisY.setHasLines(false);

        axisX.setValues(axises).setTextColor(Color.WHITE);
        List<Line> lines = new ArrayList<>();
        Line deepLine = new Line();

        List<PointValue> deepPoints = new ArrayList<>();
        for(int i=0;i<length;i++){
            HrvData data=list.get(i);
            String time=data.getTime();
            int showData=0;
            if(showType==0){
                showData=data.getBodyPressure();
            }else if(showType==1){
                showData=data.getMentalPressure();
            }else{
                showData=data.getBodyLevel();
            }
            deepPoints.add(new PointValue(i,getDisplayData(showData)));
            axises.add(new AxisValue(i).setLabel(time.split(" ")[1].toCharArray()));
        }
        if(list.size()==0) axises.add(new AxisValue(1).setLabel(" ".toCharArray()));
        deepLine.setValues(deepPoints)
                .setCubic(true)
                .setStrokeWidth(StrokeWidth*3)
                .setColor(color).setHasPoints(false);
        Bitmap bitmap=BitmapFactory.decodeResource(context.getResources(),R.drawable.hrv_chart_bg);
        LineChartData lineChartData = new LineChartData();
        lineChartData.setAxisXBottom(axisX);
        lineChartData.setAxisYLeft(axisY);
        lineChartData.setBitmap(bitmap);
        lineChartData.setValueLabelBackgroundEnabled(false);
        lines.add(deepLine);
        lineChartData.setLines(lines);
        return lineChartData;
    }
    private static int  getDisplayData(int data){
        return 3 - (100 - data) / 30;

    }
    public static LineChartData getHrvChart(Context context,String[]axisArray,HashMap<String,List<Integer>> pressureHashMap){
        Axis axisX = new Axis();
        Axis axisY = new Axis();
        if(LanguageHelp.isEnglish()){
            axisY.setMaxLabelChars(6);
        }else{
            axisY.setMaxLabelChars(2);
        }
        axisY.setTextSize(10);
        axisX.setTextSize(10);
        int color = Color.parseColor("#05a0ff");
        List<AxisValue> axisesY = new ArrayList<>();
        String[]array=context.getResources().getStringArray(R.array.history_hrvchart);
        String[] weekArrays = context.getResources().getStringArray(R.array.week_chart);
        for(int i=0;i<3;i++){
            float position=i+0.5f;
            axisesY.add(new AxisValue(position).setLabel(array[i].toCharArray()));
        }
        List<AxisValue> axises = new ArrayList<>();
        int length=axisArray.length;
        for (int i = 0; i < length; i++) {
            axises.add(new AxisValue(i).setLabel(length>7?String.valueOf(i+1).toCharArray():weekArrays[i].toCharArray()));
        }
        axisY.setValues(axisesY).setTextColor(Color.WHITE);
        axisY.setHasLines(false);

        axisX.setValues(axises).setTextColor(Color.WHITE);
        List<Line> lines = new ArrayList<>();
        Line deepLine = new Line();

        List<PointValue> deepPoints = new ArrayList<>();
        for(int i=0;i<length;i++){
            String time=axisArray[i];
            List<Integer>list=pressureHashMap.get(time);
            if(list!=null){
                int total=0;
                for(Integer data:list){
                    total+=data;
                }
                deepPoints.add(new PointValue(i,total/list.size()));
            }else{
                deepPoints.add(new PointValue(i,0));
            }
        }
        deepLine.setValues(deepPoints)
                .setCubic(true)
                .setStrokeWidth(StrokeWidth*3)
                .setColor(color).setHasPoints(false);
        Bitmap bitmap=BitmapFactory.decodeResource(context.getResources(),R.drawable.hrv_chart_bg);
        LineChartData lineChartData = new LineChartData();
        lineChartData.setAxisXBottom(axisX);
        lineChartData.setAxisYLeft(axisY);
        lineChartData.setBitmap(bitmap);
        lineChartData.setValueLabelBackgroundEnabled(false);
        lines.add(deepLine);
        lineChartData.setLines(lines);
        return lineChartData;
    }

    public static LineChartData getHeartChart(Context context,String[]axisArray,HashMap<String,List<String>>heartHashMap){
        Axis axisX = new Axis();
        Axis axisY = new Axis();
        axisY.setTextSize(10);
        axisX.setTextSize(10);
        int maxColor =Color.RED;
        List<AxisValue> axisesY = new ArrayList<>();
        List<AxisValue> axises = new ArrayList<>();
        String[]weekArray=context.getResources().getStringArray(R.array.week_chart);
        for(int i=0;i<7;i++){
            int position=40+i*20;
            axisesY.add(new AxisValue(position).setLabel(String.valueOf(position).toCharArray()));
        }
        int length=axisArray.length;
        for (int i = 0; i < length; i++) {
            axises.add(new AxisValue(i).setLabel(length>7?String.valueOf(i+1).toCharArray():weekArray[i].toCharArray()));
        }
        axisY.setValues(axisesY).setTextColor(Color.WHITE);
        axisY.setHasLines(false);
        axisX.setValues(axises).setTextColor(Color.WHITE);
        List<Line> lines = new ArrayList<>();
        Line maxLine = new Line();
        List<PointValue> deepPoints = new ArrayList<>();
        for(int i=0;i<length;i++){
            String date=axisArray[i];
            List<String>list=heartHashMap.get(date);
            if(list!=null){
                float total=0;
                float count=0;
                for(String data:list){
                    if(!TextUtils.isEmpty(data)){
                        String[]hearts=data.split(",");
                        count+=hearts.length;
                        for(String heart:hearts){
                            total+=Float.valueOf(heart);
                        }
                    }
                }
                Log.i(TAG, "getHeartChart: "+total/count);
                //  Log.i(TAG, "getDistanceChart: "+total);
                deepPoints.add(new PointValue(i,total/count));
            }else{
                deepPoints.add(new PointValue(i,0));

            }
        }
        maxLine.setValues(deepPoints)
                .setCubic(true)
                .setStrokeWidth(StrokeWidth)
                .setColor(maxColor).setHasPoints(false);

        LineChartData lineChartData = new LineChartData();
        lineChartData.setAxisXBottom(axisX);
        lineChartData.setAxisYLeft(axisY);
        lineChartData.setValueLabelBackgroundEnabled(false);
        lines.add(maxLine);

        lineChartData.setLines(lines);
        return lineChartData;
    }
    public static LineChartData getHeartDayChart(Context context,List<PathRecord>pathRecords){
        Axis axisX = new Axis();
        Axis axisY = new Axis();
        axisY.setTextSize(10);
        axisX.setTextSize(10);
        int maxColor = Color.RED;
        List<AxisValue> axisesY = new ArrayList<>();
        List<AxisValue> axises = new ArrayList<>();
        String[]weekArray=context.getResources().getStringArray(R.array.color_heart);
        for(int i=0;i<7;i++){
            int position=40+i*20;
            axisesY.add(new AxisValue(position).setLabel(String.valueOf(position).toCharArray()));
        }
        int length=pathRecords.size();

        axisY.setValues(axisesY).setTextColor(Color.WHITE);
        axisY.setHasLines(false);
        axisX.setValues(axises).setTextColor(Color.WHITE);
        List<Line> lines = new ArrayList<>();
        Line maxLine = new Line();
        List<PointValue> deepPoints = new ArrayList<>();
        for(int i=0;i<length+1;i++){
            if(i==length){
                deepPoints.add(new PointValue(i,0));

                break;
            }
            String heartString=pathRecords.get(i).getHeartListString();
            String time=pathRecords.get(i).getMDate().split(" ")[1];
           if(!TextUtils.isEmpty(heartString)){
             String[]hearts=heartString.split(",");
             float total=0;
             for(String heart:hearts){
                 total+=Float.valueOf(heart);
             }
             deepPoints.add(new PointValue(i,total/hearts.length));
               axises.add(new AxisValue(i).setLabel(time.toCharArray()));
           }else{
               deepPoints.add(new PointValue(i,0));

           }

        }
        if(pathRecords.size()==0) axises.add(new AxisValue(1).setLabel(" ".toCharArray()));

        maxLine.setValues(deepPoints)
                .setCubic(true)
                .setStrokeWidth(StrokeWidth)
                .setColor(maxColor).setHasPoints(false);

        LineChartData lineChartData = new LineChartData();
        lineChartData.setAxisXBottom(axisX);
        lineChartData.setAxisYLeft(axisY);
        lineChartData.setValueLabelBackgroundEnabled(false);
        lines.add(maxLine);

        lineChartData.setLines(lines);
        return lineChartData;
    }

    /**
     * @param context
     * @param axisArray
     * @param distanceHashMap
     * @return
     */
    public static LineChartData getDistanceChart(Context context,String[]axisArray,HashMap<String,List<String>>distanceHashMap){
        Axis axisX = new Axis();
        Axis axisY = new Axis();
        axisY.setTextSize(10);
        axisX.setTextSize(10);
        int deepSleepColor = Color.RED;
        List<AxisValue> axisesY = new ArrayList<>();
        for(int i=0;i<6;i++){
            int position=i*4;
            axisesY.add(new AxisValue(position).setLabel(String.valueOf(position).toCharArray()));
        }
        List<AxisValue> axises = new ArrayList<>();
        int length=axisArray.length;
        String[]weekArray=context.getResources().getStringArray(R.array.week_chart);

        for (int i = 0; i < length; i++) {
            axises.add(new AxisValue(i).setLabel(length>7?String.valueOf(i+1).toCharArray():weekArray[i].toCharArray()));
        }
        axisY.setValues(axisesY).setTextColor(Color.WHITE);
        axisY.setHasLines(false);
        axisX.setValues(axises).setTextColor(Color.WHITE);
        List<Line> lines = new ArrayList<>();
        Line deepLine = new Line();
        List<PointValue> deepPoints = new ArrayList<>();
        for(int i=0;i<length;i++){
            String date=axisArray[i];
            List<String>list=distanceHashMap.get(date);
            if(list!=null){
                float total=0;
                for(String data:list){//心率带回的距离 是累计
                    total+=Float.valueOf(data);
                }
                Log.i(TAG, "getDistanceChart: "+total);
                deepPoints.add(new PointValue(i,total/(length*100f)));
            }else{
                deepPoints.add(new PointValue(i,0));

            }
        }
        deepLine.setValues(deepPoints)
                .setCubic(true)
                .setHasPoints(false)
                .setStrokeWidth(StrokeWidth)
                .setColor(deepSleepColor);

        LineChartData lineChartData = new LineChartData();
        lineChartData.setAxisXBottom(axisX);
        lineChartData.setAxisYLeft(axisY);
        lineChartData.setValueLabelBackgroundEnabled(false);
        lines.add(deepLine);
        lineChartData.setLines(lines);
        return lineChartData;
    }
    public static LineChartData getDistanceDayChart(Context context, List<PathRecord>pathRecords){
        Axis axisX = new Axis();
        Axis axisY = new Axis();
        axisY.setTextSize(10);
        axisX.setTextSize(10);
        int deepSleepColor =Color.RED;
        List<AxisValue> axisesY = new ArrayList<>();
        for(int i=0;i<6;i++){
            int position=i;
            axisesY.add(new AxisValue(position).setLabel(String.valueOf(position).toCharArray()));
        }
        List<AxisValue> axises = new ArrayList<>();
        int length=pathRecords.size();
        axisY.setValues(axisesY).setTextColor(Color.WHITE);
        axisY.setHasLines(false);
        axisX.setValues(axises).setTextColor(Color.WHITE);
        List<Line> lines = new ArrayList<>();
        Line deepLine = new Line();
        List<PointValue> deepPoints = new ArrayList<>();
        for(int i=0;i<length;i++){
            PathRecord pathRecord=pathRecords.get(i);
            String date=pathRecord.getMDate().split(" ")[1];
            float distance=Float.valueOf(pathRecord.getDistanceBeat());
            deepPoints.add(new PointValue(i,distance/100f));
            axises.add(new AxisValue(i).setLabel(date.toCharArray()));
        }
        if(pathRecords.size()==0) axises.add(new AxisValue(1).setLabel(" ".toCharArray()));
        deepLine.setValues(deepPoints)
                .setCubic(true)
                .setHasPoints(false)
                .setStrokeWidth(StrokeWidth)
                .setColor(deepSleepColor);

        LineChartData lineChartData = new LineChartData();
        lineChartData.setAxisXBottom(axisX);
        lineChartData.setAxisYLeft(axisY);
        lineChartData.setValueLabelBackgroundEnabled(false);
        lines.add(deepLine);
        lineChartData.setLines(lines);
        return lineChartData;
    }
    public static LineChartData getTimeChart(Context context,String[]axisArray,HashMap<String,List<String>>timeHashMap){
        Axis axisX = new Axis();
        Axis axisY = new Axis();
        axisY.setTextSize(10);
        axisX.setTextSize(10);
        int deepSleepColor = Color.RED;
        List<AxisValue> axisesY = new ArrayList<>();
        String[]weekArray=context.getResources().getStringArray(R.array.week_chart);

        for(int i=0;i<7;i++){
            String y=String.format("%2d",i)+"H";
            axisesY.add(new AxisValue(i*60).setLabel(y.toCharArray()));
        }
        List<AxisValue> axises = new ArrayList<>();
        float length=axisArray.length;
        for (int i = 0; i < length; i++) {
            axises.add(new AxisValue(i).setLabel(length>7?String.valueOf(i+1).toCharArray():weekArray[i].toCharArray()));
        }
        axisY.setValues(axisesY).setTextColor(Color.WHITE);
        axisY.setHasLines(false);
        axisX.setValues(axises).setTextColor(Color.WHITE);
        List<Line> lines = new ArrayList<>();
        Line deepLine = new Line();
        List<PointValue> deepPoints = new ArrayList<>();
        for(int i=0;i<length;i++){
            String date=axisArray[i];
            List<String>list=timeHashMap.get(date);
            if(list!=null){
                float total=0;
                for(String data:list){//心率带回的距离 是累计
                    total+=Float.valueOf(data);
                    Log.i(TAG, "getTimeChart: "+data);
                }
                deepPoints.add(new PointValue(i,total/(length*3600)));
            }else{
                deepPoints.add(new PointValue(i,0));
            }
        }
        deepLine.setValues(deepPoints)
                .setCubic(true)
                .setHasPoints(false)
                .setStrokeWidth(StrokeWidth)
                .setColor(deepSleepColor);

        LineChartData lineChartData = new LineChartData();
        lineChartData.setAxisXBottom(axisX);
        lineChartData.setAxisYLeft(axisY);
        lineChartData.setValueLabelBackgroundEnabled(false);
        lines.add(deepLine);
        lineChartData.setLines(lines);
        return lineChartData;
    }
    public static LineChartData getTimeDayChart(Context context,List<PathRecord>pathRecords){
        Axis axisX = new Axis();
        Axis axisY = new Axis();
        axisY.setTextSize(10);
        axisX.setTextSize(10);
        int deepSleepColor = Color.RED;
         List<AxisValue> axisesY = new ArrayList<>();
        for(int i=0;i<7;i++){
            String y=String.format("%2d",i)+"H";
            axisesY.add(new AxisValue(i*60).setLabel(y.toCharArray()));
        }
        List<AxisValue> axises = new ArrayList<>();
        float length=pathRecords.size();

        axisY.setValues(axisesY).setTextColor(Color.WHITE);
        axisY.setHasLines(false);
        axisX.setValues(axises).setTextColor(Color.WHITE);
        List<Line> lines = new ArrayList<>();
        Line deepLine = new Line();
        List<PointValue> deepPoints = new ArrayList<>();
        for(int i=0;i<length;i++){
            PathRecord pathRecord=pathRecords.get(i);
            String date=pathRecord.getMDate().split(" ")[1];
            float time=Float.valueOf(pathRecord.getMDuration());
            deepPoints.add(new PointValue(i,time/3600f));
            axises.add(new AxisValue(i).setLabel(date.toCharArray()));
        }
        if(pathRecords.size()==0) axises.add(new AxisValue(1).setLabel(" ".toCharArray()));

        deepLine.setValues(deepPoints)
                .setCubic(true)
                .setHasPoints(false)
                .setStrokeWidth(StrokeWidth)
                .setColor(deepSleepColor);

        LineChartData lineChartData = new LineChartData();
        lineChartData.setAxisXBottom(axisX);
        lineChartData.setAxisYLeft(axisY);
        lineChartData.setValueLabelBackgroundEnabled(false);
        lines.add(deepLine);
        lineChartData.setLines(lines);
        return lineChartData;
    }

    public static ColumnChartData getHeartErrorColumnChart(Context context,String[]axisArray,HashMap<String,Integer>errorHashMap) {
        Axis axisX = new Axis();
        Axis axisY = new Axis();
        axisX.setTextSize(10).setTextColor(Color.WHITE);
        axisY.setTextSize(10).setTextColor(Color.WHITE);
        int SleepColor = context.getResources().getColor(R.color.week_Sleep_color);
        String[] weekArrays = context.getResources().getStringArray(R.array.week_chart);
        List<AxisValue> axisesY = new ArrayList<>();
        List<AxisValue> axises = new ArrayList<>();
        int length=axisArray.length;
        for (int i = 0; i < length; i++) {
            axises.add(new AxisValue(i).setLabel(length>7?String.valueOf(i+1).toCharArray():weekArrays[i].toCharArray()));
            if (i >= 6) continue;
            axisesY.add(new AxisValue(i * 2).setLabel((i * 2 + "").toCharArray()));
        }
        axisY.setValues(axisesY);
        axisY.setHasLines(false);
        axisY.setHasAxisLines(true);
        axisX.setValues(axises);
        List<Column> columns = new ArrayList<>();
        List<ColumnValue> columnValues = new ArrayList<>();
        for (int i = 0; i < length; i++) {
            String time=axisArray[i];
            Integer error=errorHashMap.get(time);
            columnValues = new ArrayList<>();
            columnValues.add(new ColumnValue(error==null?0:error, SleepColor));
            Column column = new Column(columnValues);
            column.setHasRectF(true);
            columns.add(column);
        }
        ColumnChartData columnChartData = new ColumnChartData(columns);
      //  columnChartData.setFillRatio(0.2f);
        //columnChartData.setBgChartColor(context.getResources().getColor(R.color.week_chart_bg_color));
        columnChartData.setAxisXBottom(axisX);
        columnChartData.setAxisYLeft(axisY);
        return columnChartData;
    }
    public static ColumnChartData getDayHeartErrorColumnChart(Context context,List<HrvData>list) {
        Axis axisX = new Axis();
        Axis axisY = new Axis();
        axisY.setTextSize(10).setTextColor(Color.WHITE);
        axisX.setTextSize(10).setTextColor(Color.WHITE);
        int SleepColor = context.getResources().getColor(R.color.week_Sleep_color);
        List<AxisValue> axisesY = new ArrayList<>();
        List<AxisValue> axises = new ArrayList<>();
        axisY.setHasLines(false);
        axisY.setHasAxisLines(true);
        axisX.setValues(axises);
        List<Column> columns = new ArrayList<>();
        List<ColumnValue> columnValues = new ArrayList<>();
        for (int i = 0; i < 6; i++) {
            axisesY.add(new AxisValue(i * 2).setLabel((i * 2 + "").toCharArray()));
        }
        axisY.setValues(axisesY);
        for(int i=0;i<list.size();i++){
            HrvData data=list.get(i);
            String time=data.getTime();
            columnValues = new ArrayList<>();
            columnValues.add(new ColumnValue(data.getError(),SleepColor));
            Column column = new Column(columnValues);
            column.setHasRectF(true);
            columns.add(column);
            axises.add(new AxisValue(i).setLabel(time.split(" ")[1].toCharArray()));
        }
        if(list.size()==0) axises.add(new AxisValue(1).setLabel(" ".toCharArray()));

        ColumnChartData columnChartData = new ColumnChartData(columns);
        columnChartData.setAxisXBottom(axisX);
        columnChartData.setFillRatio(0.2f);
        columnChartData.setAxisYLeft(axisY);
        return columnChartData;
    }
}
